// pages/iPhone/iPhone.js
var Session = require('../../vendor/qcloud-weapp-client-sdk/lib/session.js');
var config = require('../../config.js');
var commons = require('../../commons.js');
var qcloud = require('../../vendor/qcloud-weapp-client-sdk/index');
var register = require('../../template/register/register.js');
var utils = require('../../vendor/qcloud-weapp-client-sdk/lib/utils.js');
var index = {

  /**
   * 页面的初始数据
   */
  data: {
    headName: "",
    headImgUrl: "",
    toUserInData: "",
    isOpenData:false,
    renZhengData: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this;
    qcloud.request({
      login: false,
      url: config.service.isOpenUrl,
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        if (res.data.data.fieldValue == '1') {
          that.setData({
            isOpenData: false
          })
        } else {
          that.setData({
            isOpenData: true
          })
        }
      },
      fail: function (res) {
        utils.showError('请求出错')
      },
      complete: function () {

      }
    });
  },
  // 直播间设置
  MyZhiSheZhi: function() {
    wx.navigateTo({
      url: '../mydata/mydata?xgid=0',
    })
  },
  BeginZhibo: function() {
    wx.navigateTo({
      url: '../push/index',
    })
  },
  //新建直播
  NewZhiBo: function() {
    wx.navigateTo({
      url: '../myZhiBo/NewZhiBo',
    })
  },
  //我的直播
  MyZhiBo: function() {
    wx.navigateTo({
      url: '../myZhiBo/myZhiBo',
    })
  },
  //我的关注
  MyGuanZhu: function() {
    wx.navigateTo({
      url: '../myZhiBo/myGuanZhu',
    })
  },
  //历史记录
  MyHistory: function() {
    wx.navigateTo({
      url: '../myZhiBo/myHistory',
    })
  },
  //绑定手机号
  bingiPhong() {
    if (this.data.toUserInData.is_verified == 0) {
      wx.navigateTo({
        url: '../iPhone/iPhone',
      })
    }
  },
  MyZhiBoRenZ: function() {
    wx.navigateTo({
      url: '../yanZheng/yanZheng',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    var that = this;
    qcloud.request({
      login: true,
      url: config.service.toUserInfoUrl,
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function(res) {
        that.setData({
          toUserInData: res.data.data
        });
      },
      fail: function(res) {
        utils.showError(res.message)
      },
      complete: function() {
        setTimeout(function() {
          wx.hideLoading();
          wx.stopPullDownRefresh();
        }, 500)
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.onShow();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },
  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function () {
    return {
      title: '小城市live',
      path: '/pages/index/index',
      success: function () {
        utils.showSuccess("转发成功");
      }
    };
  }
};
var data = Object.assign(index.data, register.data);
var page = Object.assign(index, register);
page.data = data;
Page(page);